﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace WSContactList
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class ContactService : System.Web.Services.WebService
    {
        //[SoapHeader("Authentication", Required = true)]
        [WebMethod]
        public Contact GetContactList(int createId)
        {
            string xmlPath = Server.MapPath(@"App_Data/Contacts.xml");
            XDocument xmldoc = XDocument.Load(xmlPath);


            Contact list = (from contact in xmldoc.Descendants("User")
                            select new Contact
                            {
                                firstname = "Isman"
                            }).FirstOrDefault();
            return list;
        }

        public ContactDetail GetContactDetail(int ContactID)
        {
            return new ContactDetail();
        }

        public void GetUserDetail()
        {

        }

        public String[] GetTitleName()
        {
            return new String[] {"Mr","Mis","Ms"};
        }
        public String[] GetPhoneType()
        {
            return new String[] {"Home","Office","Mobile"};
        }
    }

    public class Contact
    {
        public int id { get; set; }
        public String firstname { get; set; }
        public String lastname { get; set; }
        public String email { get; set; }
    }


    public class ContactDetail
    {
        public int id { get; set; }
        public String titleName { get; set; }
        public String firstname { get; set; }
        public String lastname { get; set; }
        public String[] email { get; set; }
        public Telephone[] telephone { get; set; }
        public String address { get; set; }
        public String counttry { get; set; }
        public String zipcode { get; set; }
    }

    public class Telephone{
        public String number{get;set;}
        public String type {get;set;}
    }


    public class AuthHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }
}